<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class init_user_level extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'songshu:init_user_level';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '初始化超级会员';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle($page=1)
    {
        $size = 1000;
        $begin = ($page-1)*$size;
        $all = DB::table('user_tree')->offset($begin)->limit($size)->get()->toArray();
        if(empty($all)){
            return false;
        }
        foreach($all as $item){
            if($item->td_count>=5){
                DB::table('user_tree')->update([
                    'user_level'=>1,
                ]);
                echo $item->uid."\n";
            }
        }
        $page++;
        $this->handle($page);   
    }
}
